package com.zcx.qshop.conn;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.AsyType;
import com.zcx.helper.http.note.HttpInlet;

@HttpInlet(Conn.INLET_JSON_TYPELIST)
public class JsonTypelistAsyGet extends QSAsyGet<JsonTypelistAsyGet.Info> {
	
	public String areaid, typeid;

	public JsonTypelistAsyGet(String areaid, String typeid, AsyCallBack<Info> asyCallBack) {

		super(asyCallBack);

		this.areaid = areaid;
		
		this.typeid = typeid;

		ASY_TYPE = AsyType.MAX_STALE;

 	}
	
	@Override
	public Info parser(JSONObject object) {
		
		if(object.optString("message").equals("1")){
			
			Info info = new Info();
			
			JSONArray typeTwos = object.optJSONArray("typelist");
			
			for (int i = 0; i < typeTwos.length(); i++) {
				
				TypeOne typeOne = new TypeOne();
				
				JSONObject o = typeTwos.optJSONObject(i);

				typeOne.typeid = o.optString("typeid");

				typeOne.typepic = Conn.SERVICE + o.optString("typepic");

				typeOne.typetitle = o.optString("typetitle");

				typeOne.typeinfo = o.optString("typeinfo");
				
				JSONArray typeThrees = o.optJSONArray("nexttypelist");

				if(typeThrees != null){

					for (int j = 0; j < typeThrees.length(); j++) {

						TypeTwo typeTwo = new TypeTwo();

						JSONObject oo = typeThrees.optJSONObject(j);

						typeTwo.nexttile = oo.optString("nexttile");

						typeTwo.nextid = oo.optString("nextid");

						typeOne.typeTwos.add(typeTwo);

					}

				}
				
				info.typeOnes.add(typeOne);
				
			}
			
			return info;
			
		}
		
 		return null;
	}

	public static class Info{
		
		public List<TypeOne> typeOnes = new ArrayList<TypeOne>();
		
	}

	public static class TypeOne implements Serializable{

		public String typeid, typepic, typetitle, typeinfo;

		public List<TypeTwo> typeTwos = new ArrayList<TypeTwo>();

	}

	public static class TypeTwo implements Serializable{

		public String nexttile, nextid = "";

	}
	
}
